package cn.jufuns.util;

import java.util.List;

import org.apache.commons.lang.StringUtils;

public class PhoneUtil {

	    public PhoneUtil()
	    {
	    }
	    /**
	     * 电信号码段
	     * @param number
	     * @return
	     */
	    public static boolean isTelecom(String number)
	    {
	        return StringUtils.isNotBlank(number) && CommonUtil.isMatch(number, "\\d{11}") && ArrayUtil.contains(TELECOM_PREFIX, StringUtils.left(number, 3));
	    }
	    /**
	     * 联通号码段
	     * @param number
	     * @return
	     */
	    public static boolean isUnicom(String number)
	    {
	        return StringUtils.isNotBlank(number) && CommonUtil.isMatch(number, "\\d{11}") && ArrayUtil.contains(UNICOM_PREFIX, StringUtils.left(number, 3));
	    }
	    /**
	     * 移动号码段
	     * @param number
	     * @return
	     */
	    public static boolean isMobile(String number)
	    {
	        return StringUtils.isNotBlank(number) && CommonUtil.isMatch(number, "\\d{11}") && ArrayUtil.contains(MOBILE_PREFIX, StringUtils.left(number, 3));
	    }

//	    private static String getAreacodeByHcode(String phonenumber, List mobileHeadList)
//	    {
//	        for(int i = 0; i < mobileHeadList.size(); i++)
//	        {
//	            TMobileHead tmh = (TMobileHead)mobileHeadList.get(i);
//	            if(tmh != null && phonenumber.startsWith(tmh.getHeadnum()))
//	                return tmh.getHeadzone();
//	        }
//
//	        return null;
//	    }
//
//	    public static String getAreacode(String phonenumber, List mobileHeadList)
//	    {
//	        if(StringUtils.isBlank(phonenumber))
//	            throw new RuntimeException((new StringBuilder(String.valueOf(phonenumber))).append("\u7535\u8BDD\u53F7\u7801\u4E3A\u7A7A").toString());
//	        String areacode = null;
//	        if(phonenumber.startsWith("1") && phonenumber.length() == 11)
//	            return getAreacodeByHcode(phonenumber, mobileHeadList);
//	        if(phonenumber.startsWith("0") && phonenumber.length() > 3)
//	            if(ArrayUtil.contains(CODE_3BIT, phonenumber.substring(0, 3)))
//	                areacode = phonenumber.substring(0, 3);
//	            else
//	                areacode = phonenumber.substring(0, 4);
//	        return areacode;
//	    }

	    public static void main(String args[])
	    {
	        String s = "17725008300";
	        System.out.println(isTelecom(s));
	        System.out.println(isUnicom(s));
	        System.out.println(isMobile(s));
	    }

	    public static final String TELECOM_PREFIX[] = {
	        "153", "133", "189", "180", "181", "177"
	    };
	    public static final String UNICOM_PREFIX[] = {
	        "186", "185", "156", "132", "131", "130", "155", "145", "176"
	    };
	    public static final String MOBILE_PREFIX[] = {
	        "139", "138", "137", "136", "135", "134", "159", "158", "152", "151", 
	        "150", "182", "183", "184", "157", "188", "187", "147"
	    };
	    public static final String CODE_3BIT[] = {
	        "010", "020", "021", "028", "022", "024", "023", "027", "029", "025"
	    };

	}

